package com.zbw.bleeleweight.Activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.zbw.bleeleweight.R;
import com.zbw.weightlibrary.Connector.IBleControl;
import com.zbw.weightlibrary.Connector.IinfoCallback;
import com.zbw.weightlibrary.Connector.NewWeight;

/**
 * 作者 ：Wesley
 * 时间 ：2023-10-18 14:06
 * 这个类是干嘛的？：Test1Activity
 */
public class Test1Activity extends AppCompatActivity {
   private TextView text;
   private IBleControl mNewWeight;

   @Override
   protected void onCreate(@Nullable Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_test1);

      text = findViewById(R.id.text);

      mNewWeight = NewWeight.getInstance().NewControl(NewWeight.OnePlusOne, this,new IinfoCallback() {
         @Override
         public void onConnect(String msg, boolean result) {
            showText(msg);
         }

         @Override
         public void onDisconnect(String msg, boolean result) {
            showText(msg);
         }

         @Override
         public void onGetWeight(String String, boolean isSta) {
            if(isSta){
               showText("稳定"+String);
            }else{
               showText("不稳定"+String);
            }
         }
      },null);

      findViewById(R.id.bottom2).setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            mNewWeight.bleConnect();
         }
      });

      findViewById(R.id.bottom3).setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            mNewWeight.getWeight();
         }
      });

      findViewById(R.id.bottom4).setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            mNewWeight.stopWeight();
         }
      });

      findViewById(R.id.bottom5).setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            mNewWeight.bleDisconnect();
         }
      });
   }

   private void showText(final String msg){
      runOnUiThread(new Runnable() {
         @Override
         public void run() {
            text.setText(msg);

         }
      });
   }

}
